home *** CD-ROM | disk | FTP | other *** search
/ Amiga Plus 1995 #5 & #6 / Amiga Plus CD - 1995 - No. 5 and 6.iso / pd / spiele / gnuchess / src / test / chesstest / testgen.c < prev    next >
C/C++ Source or Header  |  1995-07-02  |  3KB  |  124 lines

  1. #include <stdio.h>
  2. #include <strings.h>
  3. /* convert fen notation to gnu save format */
  4. char            b[8][8];
  5. char            fn[12],*color, *colort;
  6. int             i, j, k, l;
  7. int             r, c;
  8. int        eps;
  9. int timec,timem,times;
  10. char           *p, *q;
  11. FILE           *F, *O, *W, *R;
  12. int             wq, wk, bq, bk;
  13. char            in[512];
  14. char            move[512],*q;
  15. /*                        */
  16. /*        testgen file testx bk time-min moves time-sec */
  17. /*                         */
  18. int count = 0;
  19. int countx = 0;
  20. char name[100];
  21. char namer[100];
  22. main(argc,argv)
  23. int argc;
  24. char *argv[];
  25. {
  26.     k = 1;
  27.     F = fopen(argv[1], "r");
  28. /*
  29.     W = fopen(argv[3], "w");
  30.  
  31.     fprintf(W,"0 0\n");
  32. */
  33.     timec = atoi(argv[4])*6000;
  34.     timem = atoi(argv[5]);
  35.     times = atoi(argv[6]);
  36.         timec=timec+ ( times*100);
  37.  
  38. count =100;
  39.     while (fgets(in, 512, F) != NULL) {
  40.         if(strncmp("begin",in,4) == 0)continue;
  41.         if(strncmp(in,"\n",1) == 0)continue;
  42.         if(strncmp(in,"#",1) == 0)continue;
  43.         if(strncmp(in,"\t",1) == 0)continue;
  44.         if (strncmp(" ", in, 1) != 0) {
  45.         count++;
  46.     if(count > 99){
  47.         count = 0; countx++;
  48.             sprintf(name,"%s%02d",argv[3],countx);
  49.             sprintf(namer,"%s.%s%02d.ANS",argv[1],argv[3],countx);
  50. if(countx > 1){
  51.         fprintf(W,"quit\n"); fclose(W);}
  52.          W = fopen(name,"w");
  53.          R = fopen(namer,"w");
  54.         fprintf(W,"0 0\n");
  55.     }
  56.     fprintf(W,"get\n");
  57.             wq = wk = bq = bk = 10;
  58.             for (i = 0; i < 8; i++) {
  59.                 for (j = 0; j < 8; j++) {
  60.                     b[i][j] = '.';
  61.                 }
  62.             }
  63.             p = in;
  64.             r = 0;
  65.             c = 0;
  66.             while (r<8 && *p != ' ') {
  67.                 if (isdigit(*p)) {
  68.                     c += (*p - '0');
  69.                 } else if (*p == '/') {
  70.                     r++;
  71.                     c = 0;
  72.                 } else {
  73.                     if(isupper(*p))*p = tolower(*p);
  74.                     else *p = toupper(*p);
  75.                     b[r][c] = *p;
  76.                     c++;
  77.                 }
  78.                 p++;
  79.  
  80.             }
  81.             if(*p == 'w') {color = "White";colort = "white";}
  82.              else {color = "Black";colort = "black";}
  83.             p += 2;
  84.             sprintf(fn, "%s%03d", argv[2],k);
  85. /* at Right move */
  86.             q = move;
  87.             while(*p != ' '){ 
  88.                 if(isupper(*p)){p++; continue;}
  89.                 if(*p == 'x'){ p++; continue;}
  90.                 if(*p == '+'){ p++; continue;}
  91.                 if(*p == '!'){ p++; continue;}
  92.                 if(*p == '?'){ p++; continue;}
  93.                 if(*p == '='){ p++; continue;}
  94.                 *q++ = *p++;
  95.             }
  96.             *q++ = '\0';
  97.             fprintf(R,"My move is: %s\n",move);
  98.             k++;
  99.             O = fopen(fn, "w");
  100.             fprintf(W, "%s\n",fn);
  101.             fprintf(W, "level %d %d:%d\n",timem,timec/6000,timec%6000);
  102.             fprintf(W,"%s\npost\ngo\n",colort);
  103.             fprintf(O, "White computer Black Human 1 eps %d # To move %s correct %s\nCastled White false Black false # ep \nTimeControl 0 Operator Time 0\nWhite Clock %d Moves %d\nBlack Clock %d Moves %d\n\n", eps,color,move,timec,timem,timec,timem);
  104.             for (r = 0; r < 8; r++) {
  105.                 fprintf(O, "%c ", '0' + r);
  106.                 for (c = 0; c < 8; c++) {
  107.                     fprintf(O, "%c", b[r][c]);
  108.                 }
  109.                 if (r == 0)
  110.                     fprintf(O, " %d 10 10 10 %d 10 10 %d\n", bq, ((bq + bk) > 10) ? 10 : 0, bk);
  111.                 else if (r == 7)
  112.                     fprintf(O, " %d 10 10 10 %d 10 10 %d\n", wq, ((wq + wk) > 10) ? 10 : 0, wk);
  113.                 else
  114.                     fprintf(O, " 10 10 10 10 10 10 10 10\n");
  115.             }
  116.             fprintf(O, "  abcdefgh\n\nmove  score depth  nodes  time flags capture color\n");
  117.             fclose(O);
  118.     }
  119. }
  120. fprintf(W, "quit\n");
  121. fclose(W);
  122. fclose(R);
  123. }
  124.